using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;

using MvcApplication3.Models;

namespace MvcApplication3.Controllers
{
    public class BreukController : Controller
    {
        //
        // GET: /Breuk/
        BreukRepository repo = new BreukRepository();

        public ActionResult ViewBreuken()
        {
            var breuken = repo.GetBreuken();
            return View(breuken);
        }

        public ActionResult MaakBreuken()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult MaakBreuken(int aantal, int ondergrens, int bovengrens)
        {
            Random random = new Random((int)DateTime.Now.Ticks);
            for (int i = 0; i < aantal; i++)
            {
                int teller = random.Next(ondergrens, bovengrens);
                int noemer = random.Next(ondergrens, bovengrens);
                repo.AddBreuk(teller, noemer);

            }
            return RedirectToAction("ViewBreuken") ;
        }

        public ActionResult EditBreuk(long id)
        {
            Breuk b = repo.GetBreuk(id);
            return View(b);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult EditBreuk(Breuk breuk)
        {
            repo.EditBreuk(breuk);
            return RedirectToAction("ViewBreuken");
        }

        public ActionResult DeleteBreuk(long id)
        {
            repo.DeleteBreuk(id);
            return RedirectToAction("ViewBreuken");
        }

    }
}
